/*
 * Authors - Dustin Striplin, Samba R
 */

package TableModels;

import java.util.ArrayList;


import Model.Manuscript;
import Model.Review;


/*
 * This class is used by the table. This class defines the format of the table.
 */


public class ReviewerTemplate extends MasterTable {
	
	
	private static final long serialVersionUID = 1L;
	private String[] columnNames = {"Title", "Author", "Reviews"};
	private ArrayList<ArrayList<Object>> data;  //2D ArrayList containing the individual cells in the table
	private ArrayList<Manuscript> manuscripts;		//saved to store data that is hidden from the table.
	
	
	
	/**
	 * @author Samba R, Dustin Striplin
	 * @param the_data the manuscripts to store
	 * @param name The namme of the reviewer
	 * @param conference The conference in question
	 */
	public ReviewerTemplate(final ArrayList<Manuscript> the_data,String name,String conference) {
		manuscripts = the_data;
		data = new ArrayList<ArrayList<Object>>();
		storeData(the_data,name,conference);
	}

	/**
	 * @author Dustin Striplin
	 * @return the column name
	 */
    public String getColumnName(int col) {
        return columnNames[col];
    }
    
    /**
     * returns a link to the manuscript.
     * @author Dustin Striplin
     * @param row the desired row.
     * @return the link
     */
    public String getManuscriptLink(int row) {
    	return manuscripts.get(row).getLink();
    }
    
    /**
     * Returns an ArrayList with the reviews
     * @author Dustin Striplin
     */
    public ArrayList<Review> getReviews(int row) {
    	return manuscripts.get(row).getReviews();
    }
    
    
    
	/**
	 * Returns the number of columns
	 */
	@Override
	public int getColumnCount() {
		return columnNames.length;
	}
	
	/**
	 * 	Returns the most specific superclass for all the cell values in the column.
	 */
	public Class<?> 	getColumnClass(int col) {
		return getValueAt(0, col).getClass();
	}

	
	/**
	 * Returns the number of rows.
	 */
	@Override
	public int getRowCount() {
		return data.size();
	}
	
	
	@Override
	public Object getValueAt(int row, int column) {
		return data.get(row).get(column);
	}
	
	
	@Override
	public void setValueAt(Object aValue, int row, int col) {
		data.get(row).set(col, aValue);
		fireTableCellUpdated(row, col);
	}
	
	
	/**
	 * Returns true if a column is editable, false otherwise.
	 * @author Dustin Striplin
	 * @param row the row
	 * @param col the column
	 * @return always returns false
	 */
	@Override
	public boolean isCellEditable(int row, int col) {
		return false;
	}
	
	/**
	 * Stores all of the data a reviewer would need.
	 ** @author Samba R, Dustin Striplin
	 * @param data
	 */
	private void storeData(final ArrayList<Manuscript> the_data,String name,String conference) {
		int i = 0;
		for(Manuscript m: the_data) {  //Represents a row
			for(int j=0;j<m.getReviews().size();j++) {
				if( m.getConference().getName().equals(conference) && m.getReviews().get(j).getReviewer().equals(name)){				
					data.add(new ArrayList<Object>());	//create a new ArrayList that represents a single paper
					data.get(i).add(m.getTitle());		//All of the stuff in the for loop represents
					data.get(i).add(m.getAuthor());		//a column in the row.					
					data.get(i).add(m.getReviews().get(j).getReviewLink());	
				}
			}
			i++;
		}
	}												

}